package cn.baimo.tools;

import java.util.Random;

/**
 * ClassName: NumberTools
 * Description:数字工具，包含：
 * 随机返回0或1、随机生成指定范围数字、随机生成Email、随机生成手机号
 * date: 2020/8/24 0024 17:15:22
 *
 * @author BaiMo
 * @since JDK 1.8
 */
public class NumberTools {
    private static final String[] email_suffix = "@gmail.com,@yahoo.com,@msn.com,@hotmail.com,@aol.com,@ask.com,@live.com,@qq.com,@0355.net,@163.com,@163.net,@263.net,@3721.net,@yeah.net,@googlemail.com,@126.com,@sina.com,@sohu.com,@yahoo.com.cn".split(",");
    private static String base = "abcdefghijklmnopqrstuvwxyz0123456789";
    private static String[] telFirst = "134,135,136,137,138,139,150,151,152,157,158,159,130,131,132,155,156,133,153".split(",");

    /**
     * Description: 随机返回0或1
     *
     * @param
     * @return 随机0或1
     * @author: BaiMo
     * @date: 2020/4/25 0025 19:51:53
     */
    public static int getRandom0Or1() {
        Random random = new Random();
        return random.nextInt(2);
    }

    /**
     * Description: 随机生成指定范围数字
     *
     * @param start: 开始范围
     * @param end:   结束范围
     * @return 随机数
     * @author BaiMo
     * @date 2020/4/24 0024 23:55:36
     */
    public static int getRandom(int start, int end) {
        return (int) (Math.random() * (end - start + 1) + start);
    }


    /**
     * Description: 随机生成Email
     *
     * @param Min:最小长度
     * @param Max:最大长度
     * @date: 2020/4/24 0024 23:59:25
     * @author BaiMo
     * @return: 随机Email
     */
    public static String getEmail(int Min, int Max) {
        int length = getRandom(Min, Max);
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = (int) (Math.random() * base.length());
            sb.append(base.charAt(number));
        }
        sb.append(email_suffix[(int) (Math.random() * email_suffix.length)]);
        return sb.toString();
    }


    /**
     * Description: 随机生成手机号
     *
     * @author: BaiMo
     * @date: 2020/4/24 0024 23:50:58
     * @param: null
     * @return: 手机号
     */
    public static String getPhone() {
        int index = getRandom(0, telFirst.length - 1);
        String first = telFirst[index];
        String second = String.valueOf(getRandom(1, 888) + 10000).substring(1);
        String thrid = String.valueOf(getRandom(1, 9100) + 10000).substring(1);
        return first + second + thrid;
    }

}
